const { Job } = require("../model");


// 改某一属性
exports.updateJobParams = async (req, res, next) => {
  try {
    const job = await Job.findByIdAndUpdate(req.params.id, {
      $set: req.body
    })
    if (job) {
      res.status(200).json({
        code: 200,
        msg: "success",
      });
    } else {
      res.status(200).json({
        code: 500,
        msg: "修改失败",
      });
    }
    
  } catch (error) {
    next(error);
  }
};
// 查
exports.getJob = async (req, res, next) => {
  try {
    // 模糊查询
    // find({name:/程序员/}) 
    const items = await Job.find();
    res.status(200).json({
      code: 200,
      data: items,
    });
  } catch (error) {
    next(error);
  }
};
// 通过查询条件查
exports.jobFilter = async (req, res, next) => {
  try {
    // 模糊查询
    const items = await Job.find({
      publisherId: req.body.publisherId
    });
    res.status(200).json({
      code: 200,
      data: items,
    });
  } catch (error) {
    next(error);
  }
};
// 通过id查找
exports.getJobById = async (req, res, next) => {
  try {
    const items = await Job.findById(req.params.id);
    res.status(200).json({
      code: 200,
      data: items,
    });
  } catch (error) {
    next(error);
  }
};
// 增
exports.addJob = async (req, res, next) => {
  try {
    const model = new Job(req.body);
    await model.save();
    res.status(200).json({
      code: 200,
      msg: "success",
    });
  } catch (error) {
    next(error);
  }
};
// 删
exports.deleteJob = async (req, res, next) => {
  try {
    const rs = await Job.findByIdAndDelete(req.params.id)
    if (rs) {
      res.status(200).json({
        code: 200,
        msg: '删除成功'
      });
    }
  } catch (error) {
    next(error);
  }
};


exports.getJobSalary = async (req, res, next) => {
  res.status(200).json({
    code: 200,
    data: ['3K以下', '3K~5K', '5K~8K', '8K~10K', '10K~15K', '15K以上'],
  });
};

exports.getJobTags = async (req, res, next) => {
  res.status(200).json({
    code: 200,
    data: ['财富中国500强', '创新企业100强', '制造业500强', '高薪技术企业', '天使轮', '独角兽'],
  });
};

exports.getJobExperience = async (req, res, next) => {
  res.status(200).json({
    code: 200,
    data: ['应届生', '1年以内', '1~3年', '3~5年', '5~10年', '10年以上'],
  });
};

exports.getJobLocation = async (req, res, next) => {
  res.status(200).json({
    code: 200,
    data: ['全国', '北京', '上海', '南京', '广州', '成都', '重庆'],
  });
};

exports.getXuelis = async (req, res, next) => {
  res.status(200).json({
    code: 200,
    data: ['专科', '本科', '研究生'],
  });
};

exports.getJobTypes = async (req, res, next) => {
  res.status(200).json({
    code: 200,
    data: ['IT互联网', '房地产', '金融', '消费品', '汽车制造', '医疗化工'],
  });
};